﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Windows;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using DiscoveryLogic.Analytics.DataObjects;
using DiscoveryLogic.Analytics.DataObjects.Networks;
using DiscoveryLogic.Analytics.DataObjects.Visuals;
using DiscoveryLogic.Analytics.Modules.Nodes;
using DiscoveryLogic.Common.Utilities;
using UserControl=System.Windows.Controls.UserControl;

namespace DiscoveryLogic.Analytics.Modules.VisualSettings
{
    /// <summary>
    /// Interaction logic for VerticeVisualSetting.xaml
    /// </summary>
    public partial class VerticeVisualSetting : UserControl
    {
        public delegate void OnNetworkVisualUpdated(NetworkVisual netVisual);
        public event OnNetworkVisualUpdated NetworkVisualUpdated;

        private Network _Network;
        private NetworkVisual _NetVisual;
        private List<EntityType> _ContainedEntityTypes;

        public VerticeVisualSetting(string networkName)
        {
            InitializeComponent();
            this._Network = Network.Read(networkName);
            this._NetVisual = NetworkVisual.Read(networkName);
            Network network = Network.Read(networkName);
            this._ContainedEntityTypes=new List<EntityType>();
            foreach(EntityBase entity in network.Records)
            {
                if(!_ContainedEntityTypes.Contains(entity.EntityType))
                    _ContainedEntityTypes.Add(entity.EntityType);
            }
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            this.cboEntityTypes.Items.Clear();
            foreach(EntityType entityType in this._ContainedEntityTypes)
            {
                this.cboEntityTypes.Items.Add(entityType.ToString());
            }
            this.cboShape.Items.Clear();
            foreach(VerticeShape shape in Enum.GetValues(typeof(VerticeShape)))
            {
                this.cboShape.Items.Add(shape.ToString());
            }
            this.cboSizeMeasure.Items.Clear();
            foreach(DynamicVerticeSizeMeasure sizeMeasure in Enum.GetValues(typeof(DynamicVerticeSizeMeasure)))
            {
                this.cboSizeMeasure.Items.Add(sizeMeasure.ToString());
            }

            if (this.cboEntityTypes.Items.Count > 0)
                this.cboEntityTypes.SelectedIndex = 0;
        }

        private void btnBrowseIcon_Click(object sender, RoutedEventArgs e)
        {
            if (this.cboShape.SelectedIndex >= 0 && this.cboEntityTypes.SelectedIndex >= 0)
            {
                EntityType entityType =
                    (EntityType)Enum.Parse(typeof(EntityType), this.cboEntityTypes.SelectedItem.ToString());
                
                VerticeVisual vV = this._NetVisual.EntityVisuals[entityType];
                VerticeShape shape =
                    (VerticeShape)Enum.Parse(typeof(VerticeShape), this.cboShape.SelectedItem.ToString());
                if (shape == VerticeShape.Custom)
                {
                    OpenFileDialog dlg = new OpenFileDialog();
                    dlg.Filter = "Image files(*.png;*.gif;*.bmp;*.jpg)|*.png;*.gif;*.bmp;*.jpg;*.ico|All files(*.*)|*.*";
                    dlg.InitialDirectory = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                    if (dlg.ShowDialog() == DialogResult.OK)
                    {
                        string imgFileName = System.IO.Path.GetFileName(dlg.FileName);
                        vV.Icon = imgFileName;
                    }
                }
                else
                {
                    Microsoft.Samples.CustomControls.ColorPickerDialog cPicker
                        = new Microsoft.Samples.CustomControls.ColorPickerDialog();
                    cPicker.StartingColor = vV.Color;
                    bool? dialogResult = cPicker.ShowDialog();
                    if (dialogResult != null && (bool)dialogResult)
                    {
                        vV.Color = cPicker.SelectedColor;
                    }
                }
                this.UpdateVisualDisplay(vV);
            }
        }

        private void PopulateEntityFlags(EntityType entityType)
        {
            List<string> flags=new List<string>();
            this.cboFlagColors.Items.Clear();
            foreach(EntityBase entity in this._Network.Records)
            {
                if(entity.EntityType==entityType)
                {
                    if(!string.IsNullOrEmpty(entity.Flag))
                    {
                        if(!flags.Contains(entity.Flag))
                            flags.Add(entity.Flag);
                    }
                }
            }
            if(flags.Count>0)
            {
                foreach (string flag in flags)
                    this.cboFlagColors.Items.Add(flag);
            }
        }

        private string MoveToImageFolder(string srcImgFilePath)
        {
            string binFolderPath = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            if (binFolderPath.ToLower().EndsWith("\\debug"))
                binFolderPath = binFolderPath.Substring(0, binFolderPath.LastIndexOf("\\"));
            if (binFolderPath.ToLower().EndsWith("\\release"))
                binFolderPath = binFolderPath.Substring(0, binFolderPath.LastIndexOf("\\"));
            if (binFolderPath.ToLower().EndsWith("\\bin"))
                binFolderPath = binFolderPath.Substring(0, binFolderPath.LastIndexOf("\\"));
            string imgFolderPath = System.IO.Path.Combine(binFolderPath, "images");
            string tgtFilePath = System.IO.Path.Combine(imgFolderPath, System.IO.Path.GetFileName(srcImgFilePath));
            if(!System.IO.File.Exists(tgtFilePath))
                System.IO.File.Copy(srcImgFilePath,tgtFilePath);
            return System.IO.Path.GetFileName(srcImgFilePath);
        }

        private void btnBrowseSelectedIcon_Click(object sender, RoutedEventArgs e)
        {
            if (this.cboShape.SelectedIndex >= 0 && this.cboEntityTypes.SelectedIndex >= 0)
            {
                EntityType entityType =
                    (EntityType)Enum.Parse(typeof(EntityType), this.cboEntityTypes.SelectedItem.ToString());
                VerticeVisual vV = this._NetVisual.EntityVisuals[entityType];
                VerticeShape shape =
                    (VerticeShape)Enum.Parse(typeof(VerticeShape), this.cboShape.SelectedItem.ToString());
                if (shape == VerticeShape.Custom)
                {
                    OpenFileDialog dlg = new OpenFileDialog();
                    dlg.Filter = "Image files(*.png;*.gif;*.bmp;*.jpg)|*.png;*.gif;*.bmp;*.jpg;*.ico|All files(*.*)|*.*";
                    dlg.InitialDirectory = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                    if (dlg.ShowDialog() == DialogResult.OK)
                    {
                        string imgFileName = System.IO.Path.GetFileName(dlg.FileName);
                        vV.SelectedIcon = imgFileName;
                    }
                }
                else
                {
                    Microsoft.Samples.CustomControls.ColorPickerDialog cPicker
                        = new Microsoft.Samples.CustomControls.ColorPickerDialog();
                    cPicker.StartingColor = vV.SelectedColor;
                    bool? dialogResult = cPicker.ShowDialog();
                    if (dialogResult != null && (bool)dialogResult)
                    {
                        vV.SelectedColor = cPicker.SelectedColor;
                    }
                }
                this.UpdateVisualDisplay(vV);
            }
        }


        private void btnApply_Click(object sender, RoutedEventArgs e)
        {
            this._NetVisual.Save();
            if (this.NetworkVisualUpdated != null)
                this.NetworkVisualUpdated(this._NetVisual);

            if(this.Parent is Window)
            {
                ((Window)this.Parent).Close();
            }
        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            if (this.Parent is Window)
            {
                ((Window)this.Parent).Close();
            }
        }

        private void Slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            this.lblVerticeSize.Content = Math.Round(e.NewValue, 0);
            if(this.cboEntityTypes.SelectedIndex>=0)
            {
                EntityType entityType =
                    (EntityType)Enum.Parse(typeof(EntityType), this.cboEntityTypes.SelectedItem.ToString());
                VerticeVisual vV = this._NetVisual.EntityVisuals[entityType];
                vV.Size=new Size(sliderSize.Value,sliderSize.Value);
            }
        }

        private void rdFixed_Click(object sender, RoutedEventArgs e)
        {
            if(this.rdFixed.IsChecked.Value)
            {
                this.sliderSize.Visibility = Visibility.Visible;
                this.cboSizeMeasure.Visibility = Visibility.Hidden;
                this.rdDynamic.IsChecked = false;
                if (this.cboEntityTypes.SelectedIndex >= 0 && this.cboSizeMeasure.SelectedIndex >= 0)
                {
                    EntityType entityType =
                        (EntityType)Enum.Parse(typeof(EntityType), this.cboEntityTypes.SelectedItem.ToString());
                    VerticeVisual vV = this._NetVisual.EntityVisuals[entityType];
                    vV.SizeMeasure = DynamicVerticeSizeMeasure.Fixed;
                }
            }
            else
            {
                this.sliderSize.Visibility = Visibility.Hidden;
                this.cboSizeMeasure.Visibility = Visibility.Visible;
                this.rdDynamic.IsChecked = true;
                if (this.cboEntityTypes.SelectedIndex >= 0 && this.cboSizeMeasure.SelectedIndex >= 0)
                {
                    EntityType entityType =
                        (EntityType)Enum.Parse(typeof(EntityType), this.cboEntityTypes.SelectedItem.ToString());
                    VerticeVisual vV = this._NetVisual.EntityVisuals[entityType];
                    vV.SizeMeasure =
                        (DynamicVerticeSizeMeasure)
                        Enum.Parse(typeof(DynamicVerticeSizeMeasure), this.cboSizeMeasure.SelectedItem.ToString());
                }
            }
        }

        private void rdDynamic_Click(object sender, RoutedEventArgs e)
        {
            if (this.rdDynamic.IsChecked.Value)
            {
                this.sliderSize.Visibility = Visibility.Hidden;
                this.cboSizeMeasure.Visibility = Visibility.Visible;
                this.rdFixed.IsChecked = false;
                if (this.cboEntityTypes.SelectedIndex >= 0 && this.cboSizeMeasure.SelectedIndex>=0)
                {
                    EntityType entityType =
                        (EntityType) Enum.Parse(typeof (EntityType), this.cboEntityTypes.SelectedItem.ToString());
                    VerticeVisual vV = this._NetVisual.EntityVisuals[entityType];
                    vV.SizeMeasure =
                        (DynamicVerticeSizeMeasure)
                        Enum.Parse(typeof(DynamicVerticeSizeMeasure), this.cboSizeMeasure.SelectedItem.ToString());
                }
            }
            else
            {
                this.sliderSize.Visibility = Visibility.Visible;
                this.cboSizeMeasure.Visibility = Visibility.Hidden;
                
                this.rdFixed.IsChecked = true;
                if (this.cboEntityTypes.SelectedIndex >= 0 && this.cboSizeMeasure.SelectedIndex >= 0)
                {
                    EntityType entityType =
                        (EntityType)Enum.Parse(typeof(EntityType), this.cboEntityTypes.SelectedItem.ToString());
                    VerticeVisual vV = this._NetVisual.EntityVisuals[entityType];
                    vV.SizeMeasure = DynamicVerticeSizeMeasure.Fixed;
                }
            }
        }

        private void cboEntityTypes_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
            if(this.cboEntityTypes.SelectedIndex>=0)
            {
                EntityType entityType =
                    (EntityType) Enum.Parse(typeof (EntityType), this.cboEntityTypes.SelectedItem.ToString());
                VerticeVisual vV = this._NetVisual.EntityVisuals[entityType];
                if(vV.SizeMeasure==DynamicVerticeSizeMeasure.Fixed)
                {
                    this.rdFixed.IsChecked = true;
                    this.rdDynamic.IsChecked = false;
                    this.sliderSize.Value = vV.Size.Width;
                }
                else
                {
                    this.rdFixed.IsChecked = false;
                    this.rdDynamic.IsChecked = true;
                    // this.sliderSize.Value = vV.Size.Width;
                    this.cboSizeMeasure.Text = vV.SizeMeasure.ToString();
                }
                this.cboShape.Text = vV.Shape.ToString();
                this.rdLabelAll.IsChecked = vV.ShowLabelAll;
                this.rdLabelDegree.IsChecked = vV.ShowLabelsWhenDegreeAbove > 0;
                if(this.rdLabelDegree.IsChecked.Value)
                {
                    this.sliderDegreeLabel.Value = vV.ShowLabelsWhenDegreeAbove;
                }
                this.rdLabelNames.IsChecked = (vV.ShowLabelsForNames != null && vV.ShowLabelsForNames.Count > 0);
                if(this.rdLabelNames.IsChecked.Value)
                {
                    StringBuilder buffer=new StringBuilder();
                    foreach(string name in vV.ShowLabelsForNames)
                    {
                        buffer.AppendLine(name);
                    }
                    this.txtLabelForNames.Text = buffer.ToString();
                }
                if(!this.rdLabelAll.IsChecked.Value && 
                    !this.rdLabelDegree.IsChecked.Value && 
                    !this.rdLabelNames.IsChecked.Value)
                    this.rdNoLabel.IsChecked = true;
                else
                    this.rdNoLabel.IsChecked = false;
                this.UpdateVisualDisplay(vV);

                this.PopulateEntityFlags(entityType);

            }
        }

        private void UpdateVisualDisplay(VerticeVisual vV)
        {
            if (vV.Shape == VerticeShape.Custom)
            {
                this.icon.Visibility = Visibility.Visible;
                this.icon.Source = NodeHelper.CreateImage(vV.Icon);
                this.icon.Width = this.canvasVertice.Width;
                this.icon.Height = this.canvasVertice.Height;
                this.selectedIcon.Visibility = Visibility.Visible;
                this.selectedIcon.Source = NodeHelper.CreateImage(vV.SelectedIcon);
                this.selectedIcon.Width = this.canvasSelectedVertice.Width;
                this.selectedIcon.Height = this.canvasSelectedVertice.Height;
                this.canvasVertice.Background = new SolidColorBrush(Colors.White);
                this.canvasSelectedVertice.Background = new SolidColorBrush(Colors.White);
            }
            else
            {
                this.icon.Visibility = Visibility.Hidden;
                this.selectedIcon.Visibility = Visibility.Hidden;
                this.canvasVertice.Background = new SolidColorBrush(vV.Color);
                this.canvasSelectedVertice.Background = new SolidColorBrush(vV.SelectedColor);
            }
            this.canvasLabelColor.Background = new SolidColorBrush(vV.LabelColor);
            this.DisplayFlagColors(vV);
            this.InvalidateVisual();
        }

        private void cboShape_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
            if(this.cboEntityTypes.SelectedIndex>=0 && 
                this.cboShape.SelectedIndex>=0)
            {
                EntityType entityType =
                    (EntityType)Enum.Parse(typeof(EntityType), this.cboEntityTypes.SelectedItem.ToString());
                VerticeVisual vV = this._NetVisual.EntityVisuals[entityType];
                VerticeShape shape =
                    (VerticeShape)Enum.Parse(typeof(VerticeShape), this.cboShape.SelectedItem.ToString());
                vV.Shape = shape;
                this.UpdateVisualDisplay(vV);
            }
        }

        private void cboSizeMeasure_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
            if (this.cboEntityTypes.SelectedIndex >= 0 &&
                this.cboSizeMeasure.SelectedIndex >= 0 && 
                this.cboShape.SelectedIndex>=0)
            {
                EntityType entityType =
                    (EntityType)Enum.Parse(typeof(EntityType), this.cboEntityTypes.SelectedItem.ToString());
                VerticeVisual vV = this._NetVisual.EntityVisuals[entityType];
                VerticeShape shape =
                    (VerticeShape)Enum.Parse(typeof(VerticeShape), this.cboShape.SelectedItem.ToString());
                vV.SizeMeasure =
                    (DynamicVerticeSizeMeasure)
                    Enum.Parse(typeof (DynamicVerticeSizeMeasure), this.cboSizeMeasure.SelectedItem.ToString());
            }
        }

        #region label
        private void rdLabelAll_Click(object sender, RoutedEventArgs e)
        {
            if(this.rdLabelAll.IsChecked.Value)
            {
                this.rdNoLabel.IsChecked = false;
                this.rdLabelNames.IsChecked = false;
                this.rdLabelDegree.IsChecked = false;
            }

            if (this.cboEntityTypes.SelectedIndex >= 0)
            {
                EntityType entityType =
                    (EntityType)Enum.Parse(typeof(EntityType), this.cboEntityTypes.SelectedItem.ToString());
                VerticeVisual vV = this._NetVisual.EntityVisuals[entityType];
                vV.ShowLabelAll = this.rdLabelAll.IsChecked.Value;
            }
        }

        private void rdLabelDegree_Click(object sender, RoutedEventArgs e)
        {
            if(this.rdLabelDegree.IsChecked.Value)
            {
                this.rdNoLabel.IsChecked = false;
                this.rdLabelAll.IsChecked = false;
                this.rdLabelNames.IsChecked = false;
            }

            if (this.cboEntityTypes.SelectedIndex >= 0)
            {
                EntityType entityType =
                    (EntityType)Enum.Parse(typeof(EntityType), this.cboEntityTypes.SelectedItem.ToString());
                VerticeVisual vV = this._NetVisual.EntityVisuals[entityType];
                vV.ShowLabelsWhenDegreeAbove = (int) this.sliderDegreeLabel.Value;
            }
        }

        private void sliderDegreeLabel_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            if (this.cboEntityTypes.SelectedIndex >= 0)
            {
                EntityType entityType =
                    (EntityType)Enum.Parse(typeof(EntityType), this.cboEntityTypes.SelectedItem.ToString());
                VerticeVisual vV = this._NetVisual.EntityVisuals[entityType];
                vV.ShowLabelsWhenDegreeAbove = (int)this.sliderDegreeLabel.Value;
                this.rdLabelDegree.Content = string.Format(
                    "Show labels when degree above {0}:", (int) this.sliderDegreeLabel.Value);
            }
        }

        private void rdLabelNames_Click(object sender, RoutedEventArgs e)
        {
            if(this.rdLabelNames.IsChecked.Value)
            {
                this.rdNoLabel.IsChecked = false;
                this.rdLabelAll.IsChecked = false;
                this.rdLabelDegree.IsChecked = false;
                this.sliderDegreeLabel.Value = 0;
            }

            if (this.cboEntityTypes.SelectedIndex >= 0)
            {
                EntityType entityType =
                    (EntityType)Enum.Parse(typeof(EntityType), this.cboEntityTypes.SelectedItem.ToString());
                VerticeVisual vV = this._NetVisual.EntityVisuals[entityType];
                vV.ShowLabelsForNames=new List<string>();
                if(!string.IsNullOrEmpty(this.txtLabelForNames.Text))
                {
                    string[] names = this.txtLabelForNames.Text.Split(new char[] {'\n', '\r'});
                    foreach(string name in names)
                    {
                        if(name.Trim().Length>0)
                            vV.ShowLabelsForNames.Add(name.Trim());
                    }
                }
            }
        }

        private void txtLabelForNames_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
        {
            if(this.txtLabelForNames.Text.Length<5)
                return;
            if (this.cboEntityTypes.SelectedIndex >= 0)
            {
                EntityType entityType =
                    (EntityType)Enum.Parse(typeof(EntityType), this.cboEntityTypes.SelectedItem.ToString());
                VerticeVisual vV = this._NetVisual.EntityVisuals[entityType];
                vV.ShowLabelsForNames = new List<string>();
                if (!string.IsNullOrEmpty(this.txtLabelForNames.Text))
                {
                    string[] names = this.txtLabelForNames.Text.Split(new char[] { '\n', '\r' });
                    foreach (string name in names)
                    {
                        if (name.Trim().Length > 0)
                            vV.ShowLabelsForNames.Add(name.Trim());
                    }
                }
            }
        }

        private void rdNoLabel_Click(object sender, RoutedEventArgs e)
        {
            if (rdNoLabel.IsChecked.Value)
            {
                this.rdLabelAll.IsChecked = false;
                this.rdLabelNames.IsChecked = false;
                this.rdLabelDegree.IsChecked = false;
            }

            if (this.cboEntityTypes.SelectedIndex >= 0)
            {
                
                EntityType entityType =
                    (EntityType)Enum.Parse(typeof(EntityType), this.cboEntityTypes.SelectedItem.ToString());
                VerticeVisual vV = this._NetVisual.EntityVisuals[entityType];
                if(this.rdNoLabel.IsChecked.Value)
                {
                    vV.ShowLabelAll = false;
                    vV.ShowLabelsWhenDegreeAbove = 0;
                    vV.ShowLabelsForNames=new List<string>();
                }
            }
        }
      
        private void btnVerticeLabelColor_Click(object sender, RoutedEventArgs e)
        {
            if (this.cboEntityTypes.SelectedIndex >= 0)
            {
                EntityType entityType =
                    (EntityType)Enum.Parse(typeof(EntityType), this.cboEntityTypes.SelectedItem.ToString());
                VerticeVisual vV = this._NetVisual.EntityVisuals[entityType];
                Microsoft.Samples.CustomControls.ColorPickerDialog cPicker
                        = new Microsoft.Samples.CustomControls.ColorPickerDialog();
                cPicker.StartingColor = vV.Color;
                bool? dialogResult = cPicker.ShowDialog();
                if (dialogResult != null && (bool)dialogResult)
                {
                    vV.LabelColor = cPicker.SelectedColor;
                }
                this.UpdateVisualDisplay(vV);
            }

        }
        #endregion

        private void canvasFlagColor_MouseUp(object sender, MouseButtonEventArgs e)
        {
            Microsoft.Samples.CustomControls.ColorPickerDialog cPicker
                = new Microsoft.Samples.CustomControls.ColorPickerDialog();
            cPicker.StartingColor =((SolidColorBrush) this.canvasFlagColor.Background).Color;
            bool? dialogResult = cPicker.ShowDialog();
            if (dialogResult != null && (bool)dialogResult)
            {
                this.canvasFlagColor.Background = new SolidColorBrush(cPicker.SelectedColor);
            }
        }

        private void btnAddFlagColor_Click(object sender, RoutedEventArgs e)
        {
            if(this.cboFlagColors.SelectedIndex>=0)
            {
                string flag = this.cboFlagColors.SelectedItem.ToString();
                Color flagColor = ((SolidColorBrush) this.canvasFlagColor.Background).Color;
                string s = string.Format("{0}={1}", flag, ColorUtil.ToString(flagColor));
                if(!string.IsNullOrEmpty(this.txtFlagColors.Text))
                    this.txtFlagColors.Text += Environment.NewLine;
                    
                this.txtFlagColors.Text += s;

                this.ReadFlagColors();
            }
        }

        private void DisplayFlagColors(VerticeVisual vv)
        {
            string s = string.Empty;
            if(vv.FlagColors !=null && vv.FlagColors.Count>0)
            {
                foreach(string flag in vv.FlagColors.Keys)
                {
                    if (s.Length > 0)
                        s += Environment.NewLine;
                    s += string.Format("{0}={1}", flag, ColorUtil.ToString(vv.FlagColors[flag]));
                }
            }
            this.txtFlagColors.Text = s;
        }

        private void ReadFlagColors()
        {
            Dictionary<string,Color> flagColors=new Dictionary<string, Color>();
            if(!string.IsNullOrEmpty(this.txtFlagColors.Text))
            {
                string[] flagColors1 = this.txtFlagColors.Text.Split(new char[]{'\n','\r'});
                foreach (string flagColor in flagColors1)
                {
                    if(flagColor.Trim().Length==0)
                        continue;
                    string[] pair = flagColor.Split(new char[] {'='});
                    if(pair.Length==2)
                    {
                        string flag = pair[0];
                        Color color = ColorUtil.ParseMediaColor(pair[1]);
                        if (!flagColors.ContainsKey(flag))
                            flagColors.Add(flag, color);
                    }
                }
            }

            if (this.cboEntityTypes.SelectedIndex >= 0)
            {
                EntityType entityType =
                    (EntityType)Enum.Parse(typeof(EntityType), this.cboEntityTypes.SelectedItem.ToString());
                VerticeVisual vV = this._NetVisual.EntityVisuals[entityType];
                vV.FlagColors = flagColors;
            }
        }

        private void btnClearAllFlags_Click(object sender, RoutedEventArgs e)
        {
            this.txtFlagColors.Text = string.Empty;
            this.ReadFlagColors();
        }
    }
}
